﻿namespace RefactoringRotatingWalkInMatrixTests
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using RefactoringRotatingWalkInMatrix;

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void ZeroDimensionsTest()
        {
            MatrixRotatingWalk matrix = new MatrixRotatingWalk(0);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void NegativeDimensionsTest()
        {
            MatrixRotatingWalk matrix = new MatrixRotatingWalk(-1);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void HigherOfRangeTest()
        {
            MatrixRotatingWalk matrix = new MatrixRotatingWalk(101);
        }

        [TestMethod]
        public void OneDimensionTest()
        {
            MatrixRotatingWalk matrix = new MatrixRotatingWalk(1);

            Assert.IsTrue(matrix.ToString() == string.Format("  1{0}", Environment.NewLine));
        }

        [TestMethod]
        public void TwoDimensionTest()
        {
            MatrixRotatingWalk matrix = new MatrixRotatingWalk(2);

            Assert.IsTrue(matrix.ToString() == string.Format("  1  4{0}  3  2{0}", Environment.NewLine));
        }

        [TestMethod]
        public void ThreeDimensionTest()
        {
            MatrixRotatingWalk matrix = new MatrixRotatingWalk(3);

            Assert.AreEqual(matrix.ToString(), string.Format("  1  7  8{0}  6  2  9{0}  5  4  3{0}", Environment.NewLine));
        }

        [TestMethod]
        public void SixDimensionTest()
        {
            MatrixRotatingWalk matrix = new MatrixRotatingWalk(6);

            Assert.AreEqual(
                matrix.ToString(),
                string.Format(
                    "{0}{6}{1}{6}{2}{6}{3}{6}{4}{6}{5}{6}",
                    "  1 16 17 18 19 20",
                    " 15  2 27 28 29 21",
                    " 14 31  3 26 30 22",
                    " 13 36 32  4 25 23",
                    " 12 35 34 33  5 24",
                    " 11 10  9  8  7  6",
                    Environment.NewLine));
        }
    }
}